<template>
	<view class="bg-white" :class="{
		'blue-shadow': status === 'unread'
	}">
		<view class="box-main">
			<view class="title-bar mb-2">
				<text v-if="props.type === 'report' && props.generateStatus === '1'" class="cuIcon-loading2 text-green title-icon" style=""></text>
				<text v-else-if="props.type === 'report' && props.generateStatus === '2'" class="cuIcon-check text-blue title-icon" style=""></text>
				<text v-else-if="props.type === 'mission'" class="cuIcon-infofill text-red title-icon" style=""></text>
				<text v-else-if="props.type === 'notice'" class="cuIcon-infofill text-red title-icon" style=""></text>
				<text v-else-if="props.type === 'statistics'" class="cuIcon-form text-blue title-icon" style=""></text>
				<text v-else-if="props.type === 'rectification'" class="cuIcon-infofill text-blue title-icon" style=""></text>
				<text v-else class="cuIcon-message text-blue title-icon" style=""></text>
				
				<text class="title middle-text text-black text-bold text-ellipsis-2">{{ props.title }}</text>
				
				<text class="date text-black small-text">{{ props.date }}</text>
			</view>
			<view class="content">{{ props.content }}</view>
		</view>
		
		<view class="more-bar" @click="navMore">
			<text class="small-text text-blue">
				查看更多
			</text>
			
			<text class="cuIcon-right text-gray"></text>
		</view>
	</view>
</template>

<script setup lang="ts">
import { router } from "@/router"
import { setMessageRead } from "@/api/user.js"
import { getAIReport } from "@/api/mission.js"
import path from "path-browserify"
import store from "@/store/index.js"
import { onMounted } from "vue"
	
const props = defineProps({
	id: {
		type: Number,
		default: null
	},
	status: {
		type: String,
		default: 'unread'
	},
	title: {
		type: String,
		default: ""
	},
	date: {
		type: String,
		default: ""
	},
	content: {
		type: String,
		default: ""
	},
	type: {
		type: String,
		default: "none"
	},
	relationId: {
		type: Number,
		default: 0
	},
	generateStatus: {
		type: String,
		default: null
	}
})

const emit = defineEmits(["update:status"])

const navMore = ():void => {
	console.log(props.type)
	if (props.status === "unread") {
		setMessageRead({
			id: props.id,
			status: "2"
		})
		emit("update:status", "2")
	}
	
	if (props.type === "mission") {
		router.push("/pages/mission/mission?mission_id=" + props.relationId)
	} else if (props.type === "notice") {
		router.push("/pages/mission/mission?mission_id=" + props.relationId)
			.then(() => {
				router.push("/pages/mission/record?mission_id=" + props.relationId)
			})
	} else if (props.type === "report") {
		uni.showLoading({
			title: "查询中"
		})
		getAIReport(props.relationId)
			.then((res) => {
				uni.hideLoading()
				console.log(res)
				if (res.reportFiles) {
					const report = JSON.parse(res.reportFiles)
					if (store.getters.osName === "ios") {
						router.push({
							path: "/pages/index/word",
							params: {
								title: path.basename(report.name),
								filepath: report.url
							}
						})
					} else {
						location.href = report.url
					}
				} else {
					uni.showToast({
						icon: "none",
						title: "未查询到关联报告"
					})
				}
			})
		// router.push("/pages/mission/ai_report?mission_id=" + props.relationId)
	} else if (props.type === "statistics") {
		router.push("/pages/mission/statistics?form_id=" + props.relationId)
	} else if (props.type === "rectification") {
		router.push("/pages/mission/rectification?rect_record_id=" + props.relationId)
	}
	
}

onMounted(() => {
	console.log(store.getters.osName)
})
</script>

<style lang="stylus" scoped>
.box-main
	box-sizing border-box
	padding 40rpx
	border-bottom 2rpx solid #eee
	.title-bar
		display: flex
		align-items: center
		.title-icon
			font-size: 48rpx
			margin-right:18rpx
			min-width: 60rpx
		.title
			width 400rpx
		.date
			min-width: 100rpx
			text-align: right
	.content
		font-size 30rpx
		padding-left 66rpx
.more-bar
	display: flex
	justify-content: space-between
	padding: 24rpx 40rpx
.more-bar:active
	background-color: #eee
	
.blue-shadow
	box-shadow: 0px 0px 0.18rem rgba(181, 33, 33, 0.4)
	

</style>